package com.nciae.controller;


import com.nciae.po.Teacher;
import com.nciae.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Guoliyu
 * @since 2022-03-30
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private ITeacherService teacherService;

    @GetMapping
    public ResponseEntity<List<Teacher>> findAll(
            @RequestParam("username")String username
    ) {
        return ResponseEntity.ok(teacherService.findAll(username));
    }

    @PostMapping
    public ResponseEntity<Boolean> add(@RequestBody Teacher teacher) {
        teacherService.add(teacher);
        return ResponseEntity.ok(true);
    }

    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody Teacher teacher) {
        teacherService.update(teacher);
        return ResponseEntity.ok(true);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable("id")Long id) {
        teacherService.delete(id);
        return ResponseEntity.ok(true);
    }
}
